<!DOCTYPE html>
<html>
<head>
    <title>财务缴款单据打印</title>
<#include "../common/common.ftl"/>
</head>
<body style="overflow-y: hidden;">
<div class="layui-fluid">
    <blockquote class="layui-elem-quote layui-bg-white">
        申请提前交房【姓名：<span class="jmdf-color-red">${(contract.name)!}</span>】
        【选房号：<span class="jmdf-color-red">${(contract.chooseHouseNum)!}</span>】
        【协议编号：<span class="jmdf-color-red">${(contract.contractCode)!}</span>】
    </blockquote>
    <div class="layui-row layui-col-space15 handInMoney">
        <div class="layui-col-lg5 layui-col-md5">
            <form class="layui-form">
                <div class="layui-card">
                    <div class="layui-card-header">
                        <span class="jmdf-color-red">注：点击选择房源为提前申请交房清单，不点击默认全部！</span>
                    </div>
                    <div class="layui-card-body">
                        <table class="layui-table">
                            <tr>
                                <th style="text-align: center;min-width: 100px">所在小区</th>
                                <th style="text-align: center;min-width: 80px">户号</th>
                                <th style="text-align: center;min-width: 80px">产权人</th>
                                <th style="text-align: center;min-width: 60px">操作</th>
                            </tr>
                        <#if (houseList??)>
                            <#list houseList as house>
                                <tr>
                                    <td style="text-align: center;">${house.azProject.projectName}</td>
                                    <td style="text-align: center;">${house.houseNumStr}</td>
                                    <td style="text-align: center;">
                                        <#assign buyHousePersonHouseList=(buyHousePersonHouseMap[house.id?c])! />
                                        <#if buyHousePersonHouseList?? && buyHousePersonHouseList?size != 0>
                                            <#list buyHousePersonHouseList as buyHousePersonHouse>
                                            ${(buyHousePersonHouse.name)!}<br/>
                                            </#list>
                                        </#if>
                                    </td>
                                    <td style="text-align: center;">
                                        <input type="checkbox" name="houseId" value="${(house.id)!}" lay-skin="primary"
                                               lay-filter="filter"/>
                                    </td>
                                </tr>
                            </#list>
                        </#if>
                        <#if (carLotList??)>
                            <#list carLotList as carLot>
                                <tr>
                                    <td style="text-align: center;">${carLot.azProject.projectName}</td>
                                    <td style="text-align: center;">${carLot.houseNumStr}</td>
                                    <td style="text-align: center;">
                                        <#assign buyHousePersonCarLotList=(buyHousePersonCarLotMap[carLot.id?c])! />
                                        <#if buyHousePersonCarLotList?? && buyHousePersonCarLotList?size != 0>
                                            <#list buyHousePersonCarLotList as buyHousePersonCarLot>
                                            ${(buyHousePersonCarLot.name)!}<br/>
                                            </#list>
                                        </#if>
                                    </td>
                                    <td style="text-align: center;">
                                        <input type="checkbox" name="carLotId" value="${(carLot.id)!}"
                                               lay-skin="primary" lay-filter="filter"/>
                                    </td>
                                </tr>
                            </#list>
                        </#if>
                        <#if (storageRoomList??)>
                            <#list storageRoomList as storageRoom>
                                <tr>
                                    <td style="text-align: center;">${storageRoom.azProject.projectName}</td>
                                    <td style="text-align: center;">${storageRoom.houseNumStr}</td>
                                    <td style="text-align: center;">
                                        <#assign buyHousePersonStorageRoomList=(buyHousePersonStorageRoomMap[storageRoom.id?c])! />
                                        <#if buyHousePersonStorageRoomList?? && buyHousePersonStorageRoomList?size != 0>
                                            <#list buyHousePersonStorageRoomList as buyHousePersonStorageRoom>
                                            ${(buyHousePersonStorageRoom.name)!}<br/>
                                            </#list>
                                        </#if>
                                    </td>
                                    <td style="text-align: center;">
                                        <input type="checkbox" name="storageRoomId" value="${(storageRoom.id)!}"
                                               lay-skin="primary" lay-filter="filter"/>
                                    </td>
                                </tr>
                            </#list>
                        </#if>
                        </table>
                    </div>
                </div>
            </form>
        </div>
        <div class="layui-col-lg7 layui-col-md7">
            <div class="layui-card">
                <div class="layui-tab layui-tab-brief" id="finance">
                    <ul class="layui-tab-title">
                        <li class="layui-this refreshPDF"
                            source="/pdf/print/advanceTakeHousePrintPDF?contractId=${(contract.id)!}">申请提前交房及补充协议
                        </li>
                    </ul>
                    <iframe id="printIframe" style="width: 100%;height: 730px;margin-top: 10px"></iframe>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="/layui/layui.js" charset="utf-8"></script>
<script>
    layui.config({
        base: '/modules/' //静态资源所在路径
    }).use(['jquery', 'form', 'layer', 'element', 'jmdf'], function () {
        var $ = layui.jquery, jmdf = layui.jmdf, form = layui.form, layer = layui.layer, element = layui.element;

        //封装打印链接调用方法
        function openPdf(source) {
            var url = source + "#toolbar=0";
            $("#printIframe").attr("src", url);
        }

        //选项卡点击时改变PDF链接
        $(".printPDF").click(function () {
            var source = $(this).attr("source");
            openPdf(source);
        });

        //页面初始化时，默认加载第一个选项卡
        openPdf($("#finance li").attr("source"));

        //监听checkbox按钮，随时触发改变PDF链接
        form.on('checkbox(filter)', function (data) {
            refreshPDF();
        });

        //选项卡第一个点击时触发
        $(".refreshPDF").click(function (refreshType) {
            refreshPDF();
        });

        //刷新户型清单方法
        function refreshPDF() {
            var houseIdStr = "";
            var carLotIdStr = "";
            var storageRoomIdStr = "";
            $("input:checkbox[name='houseId']:checked").each(function () {
                houseIdStr += $(this).val() + ",";
            });

            $("input:checkbox[name='carLotId']:checked").each(function () {
                carLotIdStr += $(this).val() + ",";
            });
            $("input:checkbox[name='storageRoomId']:checked").each(function () {
                storageRoomIdStr += $(this).val() + ",";
            });
            var source = "/pdf/print/advanceTakeHousePrintPDF?contractId=${(contract.id)!}";
            if (houseIdStr.length > 0) {
                houseIdStr = houseIdStr.substring(0, houseIdStr.length - 1);
                source += "&houseIdStr=" + houseIdStr;
            }
            if (carLotIdStr.length > 0) {
                carLotIdStr = carLotIdStr.substring(0, carLotIdStr.length - 1);
                source += "&carLotIdStr=" + carLotIdStr;
            }
            if (storageRoomIdStr.length > 0) {
                storageRoomIdStr = storageRoomIdStr.substring(0, storageRoomIdStr.length - 1);
                source += "&storageRoomIdStr=" + storageRoomIdStr;
            }
            openPdf(source);
        }
    })
</script>
</html>
